package anthology.daily_question._25_01;
//https://leetcode.cn/problems/largest-combination-with-bitwise-and-greater-than-zero/description/?envType=daily-question&envId=2025-01-12
public class _2275按位与结果大于零的最长组合 {
    class Solution {
        // 计算从低到高第 k 个二进制位数值为 1 的元素个数
        public int maxlen(int[] candidates, int k) {
            int res = 0;
            for (int num : candidates) {
                if ((num & (1 << k)) != 0) {
                    res++;
                }
            }
            return res;
        }

        public int largestCombination(int[] candidates) {
            int res = 0;
            for (int i = 0; i < 24; i++) {
                // 遍历二进制位
                res = Math.max(res, maxlen(candidates, i));
            }
            return res;
        }
    }
}
